package com.wang;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;

/**
 * 基于官网的示例
 * http://www.quartz-scheduler.org/documentation/quartz-2.2.x/quick-start.html
 * @Author wlyfree
 * @Date 17:53
 */
public class SimpleDemo {
    public static void main(String[] args) throws SchedulerException {
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        //=============开始调度===============
        scheduler.start();
        //任务
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class).withIdentity("job1","group1").build();
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1","group1").startNow().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(1).repeatForever()).build();
        scheduler.scheduleJob(jobDetail,trigger);
        //关闭前给足够的执行时间
        try {
            Thread.sleep(6000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //=============必须手动关闭，否则不会终止，因为还有活动线程===============
        scheduler.shutdown();

    }
}
